package org.thanos.demo.component;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class ScheduleService {

    @SneakyThrows
    @Scheduled(fixedRate = 5000)
    @Async(value = "executorOne")
    public void demoOne() {
        log.info("start thread is {}, time is {}", Thread.currentThread().getName(), LocalDateTime.now());
        TimeUnit.SECONDS.sleep(10);
        log.info("end thread is {}, time is {}", Thread.currentThread().getName(), LocalDateTime.now());
    }

    @Scheduled(fixedDelay = 5000)
    @Async(value = "executorTwo")
    public void demoTwo() {
        log.info("thread is {}, time is {}", Thread.currentThread().getName(), LocalDateTime.now());
    }
}
